package cn.rkylin.oms.aftersale.event.vo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.fasterxml.jackson.annotation.JsonFormat;

import cn.rkylin.oms.aftersale.event.domain.AfterSaleEvent;
import cn.rkylin.oms.common.consts.EventStatus;

/**
 * 类名:AfterSaleAfterSaleEventVO <br/>
 * 作用: 售后服务数据对象. <br/>
 * 创建原因: 售后服务数据对象. <br/>
 * 创建时间: 2017年9月25日 下午1:36:46 <br/>
 * 
 * @author zhanghao
 * @version v1.0
 */
public class AfterSaleEventVO extends AfterSaleEvent {
    /**
     * 构造器：AfterSaleEventVO.
     */
    public AfterSaleEventVO() {
    }

    /**
     * serialVersionUID:自动生成的序列化编号.
     */
    private static final long serialVersionUID = 322477974402994586L;

    private static final String STATUS_EVENT_SHOW = "<span class=\"fa fa-chevron-down\" orderId =\"%s\"></span>";
    private static final String OPERATION_BTN_OPERAT = "<div class=\"btn-group %s\" id=\"operation\"><button type=\"button\" data-toggle=\"dropdown\" class=\"btn btn-xs btn-info dropdown-toggle\" pepid='afterSaleEvent'><i class=\"fa fa-phone\"></i>&nbsp;售后 &nbsp;<span class=\"caret\"></span></button><ul role=\"menu\" class=\"dropdown-menu\" id=\"operationButton%s\"><li pepid='afterSaleEventDispose'><a href=\"#\" onclick=\"disposeEvent(\'%s\',this)\" id=\"disposeEvent%s\">处理</a></li><li pepid='afterSaleEventEdit'><a href=\"#\" onclick=\"editEvent(\'%s\',this)\" id=\"editEvent%s\">修改</a></li><li pepid='afterSaleEventDelete'><a href=\"#\" onclick=\"deleteEvent(\'%s\',this)\" id=\"deleteEvent%s\">删除</a></li></div>";
    private static final String OPERATION_BTN_COMPLETE = "<button onclick=\"operationComplete(this)\" eventId=\"%s\"  type=\"button\" class=\"btn btn-success btn-xs\"  pepid='afterSaleEventComplete'><i class=\"fa fa-check-square-o\"></i>&nbsp;完成</button>";
    private static final String OPERATION_BTN_ANNUL = "<button onclick=\"operationAnnul(this)\" eventId=\"%s\" type=\"button\" class=\"btn btn-danger btn-xs\" pepid='afterSaleEventAnnul'><i class=\"fa fa-times\"></i>&nbsp;撤销</button>";

    /**
     * searchCondition:快速查询条件.
     */
    private String quickSearch;

    /**
     * paidDate:付款日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date paidDate;

    /*
     * 高级查询相关的条件
     */
    /**
     * queryFactDealUser:实际处理人
     */
    private String queryFactDealUser;
    /**
     * queryEventCreator:创建人.
     */
    private String queryEventCreator;
    /**
     * queryEventType:售后事件类型.
     */
    private String queryEventType;

    /**
     * queryDateType:日期类型.
     */
    private String queryDateType;
    /**
     * queryDateStart:开始日期.
     */
    private Date queryDateStart;
    /**
     * queryDateEnd:结束日期.
     */
    private Date queryDateEnd;

    /**
     * sonShow：展开符
     */
    private String sonShow;

    /**
     * ecTradeCode:平台交易号.
     */
    private String tradeCode;

    /**
     * 网店id
     */
    private String shopId;

    /**
     * 网店名称
     */
    private String shopName;

    /**
     * operation:操作按钮
     */
    private String operation;

    /**
     * reversePosition:转换下拉按钮的方向(取值“”，“dropup”)
     */
    private String reversePosition;

    /**
     * orderBy:排序规则.
     */
    private String orderBy;

    /**
     * 各状态计数
     */
    private Integer countPending; // 待处理
    private Integer countProcessing;// 处理中
    private Integer countComplete; // 已完成

    /**
     * queryEventStatus:售后事件状态列表（查询多个事件状态列表用）
     */
    public List queryEventStatus;

    /**
     * idArray：id列表，用于批量操作
     */
    private List<String> idArray = new ArrayList<String>();

    public String getQuickSearch() {
        return quickSearch;
    }

    public void setQuickSearch(String quickSearch) {
        this.quickSearch = quickSearch;
    }

    public String getQueryFactDealUser() {
        return queryFactDealUser;
    }

    public void setQueryFactDealUser(String queryFactDealUser) {
        this.queryFactDealUser = queryFactDealUser;
    }

    public String getQueryEventCreator() {
        return queryEventCreator;
    }

    public void setQueryEventCreator(String queryEventCreator) {
        this.queryEventCreator = queryEventCreator;
    }

    public String getQueryEventType() {
        return queryEventType;
    }

    public void setQueryEventType(String queryEventType) {
        this.queryEventType = queryEventType;
    }

    public String getQueryDateType() {
        return queryDateType;
    }

    public void setQueryDateType(String queryDateType) {
        this.queryDateType = queryDateType;
    }

    public Date getQueryDateStart() {
        return queryDateStart;
    }

    public void setQueryDateStart(Date queryDateStart) {
        this.queryDateStart = queryDateStart;
    }

    public Date getQueryDateEnd() {
        return queryDateEnd;
    }

    public void setQueryDateEnd(Date queryDateEnd) {
        this.queryDateEnd = queryDateEnd;
    }

    public String getSonShow() {
        return String.format(STATUS_EVENT_SHOW, this.getOrderId()).toString();
    }

    public void setSonShow(String sonShow) {
        this.sonShow = sonShow;
    }

    public String getTradeCode() {
        return tradeCode;
    }

    public void setTradeCode(String tradeCode) {
        this.tradeCode = tradeCode;
    }

    public String getShopId() {
        return shopId;
    }

    public void setShopId(String shopId) {
        this.shopId = shopId;
    }

    public String getShopName() {
        return shopName;
    }

    public void setShopName(String shopName) {
        this.shopName = shopName;
    }

    public Date getPaidDate() {
        return paidDate;
    }

    public void setPaidDate(Date paidDate) {
        this.paidDate = paidDate;
    }

    public String getOperation() {
        StringBuffer opButton = new StringBuffer();
        if (EventStatus.PENDING.equals(getEventStatus())) {
            // 待处理 ：可以通过下拉选择处理、修改和删除操作
            opButton.append(String.format(OPERATION_BTN_OPERAT, getReversePosition(), getEventId(), getEventId(), getEventId(), getEventId(),
                    getEventId(), getEventId(), getEventId()));
        }
        if (EventStatus.PROCESSING.equals(getEventStatus())) {
            // 处理中：可以执行完成和撤销操作
            opButton.append(String.format(OPERATION_BTN_COMPLETE, getEventId()));
            opButton.append("&nbsp;");
            opButton.append(String.format(OPERATION_BTN_ANNUL, getEventId()));
        }
        return opButton.toString();
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    public String getReversePosition() {
        return StringUtils.isEmpty(reversePosition) ? "" : reversePosition;
    }

    public void setReversePosition(String reversePosition) {
        this.reversePosition = reversePosition;
    }

    public String getOrderBy() {
        return orderBy == null ? null : orderBy.replaceAll(".*([';]+|(--)+).*", " ");// 此字段需要防止sql注入
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public Integer getCountPending() {
        return countPending;
    }

    public void setCountPending(Integer countPending) {
        this.countPending = countPending;
    }

    public Integer getCountProcessing() {
        return countProcessing;
    }

    public void setCountProcessing(Integer countProcessing) {
        this.countProcessing = countProcessing;
    }

    public Integer getCountComplete() {
        return countComplete;
    }

    public void setCountComplete(Integer countComplete) {
        this.countComplete = countComplete;
    }

    public List getQueryEventStatus() {
        return queryEventStatus;
    }

    public void setQueryEventStatus(List queryEventStatus) {
        this.queryEventStatus = queryEventStatus;
    }

    public List<String> getIdArray() {
        return idArray;
    }

    public void setIdArray(List<String> idArray) {
        this.idArray = idArray;
    }

}
